#include <stdio.h>

int main(int argc, char *argv[])
{
	int n, m, i, j, v, p, s[30001];

	scanf("%d %d", &n, &m);
	for (i=0; i<m; i++) {
		scanf("%d %d", &v, &p);

		for (j=n; j>=v; j--) {
			if (s[j-v] + v * p > s[j]) {
				s[j] = s[j-v] + v * p;
			}
		}
	}

	printf("%d\n", s[n]);

	return 0;
}
